<?php
	@session_start();
	require_once('connection.php');
	class Signup
	{
		private $userId_;
		private $email_;
		private $password_;
		private $firstName_;
		private $lastName_;
				
		function getUserId()
		{
			return $this->userId_;	
		}		
		
		function getEmail()
		{
			return $this->email_;	
		}
		
		function getPassword()
		{
			return $this->password_;	
		}
		
		function getFirstName()
		{
			return $this->firstName_;	
		}
		
		function getLastName()
		{
			return $this->lastName_;	
		}
		
		
		function setUserId($userId)
		{
			$this->userId_=$userId;
		}
		
		function setEmail($email)
		{
			$this->email_=$email;	
		}
		
		function setPassword($password)
		{
			$this->password_=$password;
		}
		
		function setFirstName($firstName)
		{
			$this->firstName_=$firstName;	
		}
		
		function setLastName($lastName)
		{
			$this->lastName_=$lastName;	
		}
		
		
		function save()
		{
			$query="INSERT INTO  login_details
			(
				user_email,
				user_password,
				user_firstname,
				user_lastname
			)
			VALUES
			(
				'" . $this->email_ . "',
				'" . $this->password_ . "',		
				'" . $this->firstName_ . "',
				'" . $this->lastName_ . "'
			)";//'" . sha1($this->password_) . "',
			$result=mysql_query($query);
			if($result!=false)
			{
				$this->userId_=mysql_insert_id();
				return $this->userId_;
			}
			else
				return false;
		}
		
		
		function load()
		{
			$query="SELECT * FROM login_details WHERE user_id='".$_SESSION['userId']."'";
			$result=mysql_query($query);
			$row=mysql_fetch_array($result,MYSQL_ASSOC);
			$this->email_=$row['user_email'];
			$this->password_=$row['user_password'];
			$this->firstName_=$row['user_firstname'];
			$this->lastName_=$row['user_lastname'];
		}
		
		
		function loginUser($userEmail, $password)
		{
			$query="SELECT * FROM login_details WHERE user_email='".$userEmail."' AND user_password='".$password."'";
			$result=mysql_query($query);
			if(mysql_num_rows($result)==1)
			{
				$row=mysql_fetch_array($result,MYSQL_ASSOC);
				$_SESSION['userId']	= $row['user_id'];
				$_SESSION['ipAddress'] = $_SERVER['REMOTE_ADDR'];
				return $row['user_id'];
			}
			else
				return false;	
		}
	}
?>